import {
  queryScene,
  addScene,
  deleteScene,
  updateScene,  
} from '@/services/security/scene';

export default {
  namespace: 'scene',
  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
  },
  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryScene, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },

    *add({ payload, callback }, { call, put }) {
      const response = yield call(addScene, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },

    *delete({ payload, callback }, { call, put }) {
      const response = yield call(deleteScene, payload);
      yield put({
        type: 'savedelete',
        payload: response,
      });
      if (callback) callback(response);
    },

    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateScene, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },

  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data  || [],        
      };
    },
  },
};
